package com.example.element.module.material

import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.common.base.AbsActivity
import com.example.element.R
import com.example.element.databinding.ActMaterialToolbarBinding

@Route(path = "/material/toolbar")
class ToolbarActivity : AbsActivity<ActMaterialToolbarBinding>() {

    override fun getLayoutId(): Int {
        return R.layout.act_material_toolbar
    }

    override fun main() {
        setSupportActionBar(mBinding.toolbar)
    }

    override fun initListener() {
    }

    /**
     * toolbar 创建菜单
     */
    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.toolbar, menu)
        return true
    }

    /**
     * toolbar 菜单点击事件
     */
    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            R.id.share -> Toast.makeText(mContext, "You checked share", Toast.LENGTH_SHORT).show()
            R.id.del -> Toast.makeText(mContext, "You checked del", Toast.LENGTH_SHORT).show()
            R.id.more -> Toast.makeText(mContext, "You checked more", Toast.LENGTH_SHORT).show()
        }
        return true
    }
}